package cn.ywyu.classfinal.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.stream.Collectors;

@Getter
@AllArgsConstructor
public enum FrameworkEnum {
    SPRING(
            "org.springframework.core.io.ClassPathResource#getInputStream",
            "char[] c=%s;is=cn.ywyu.classfinal.jar.JarDecryptor.getInstance().decryptConfigFile(this.path,is,c);",
            9999
    ),
    JFINAL(
            "com.jfinal.kit.Prop#<Prop>(java.lang.String,java.lang.String)",
            "char[] c=%s;inputStream=cn.ywyu.classfinal.jar.JarDecryptor.getInstance().decryptConfigFile(fileName,inputStream,c);",
            62
    );

    /**
     * 类方法
     */
    private final String classMethod;
    /**
     * java代码
     */
    private final String javaCode;
    /**
     * 行
     */
    private final int line;

    /**
     * 解析java代码
     */
    public String parseJavaCode(char[] pwdChars) {
        return String.format(
                javaCode,
                String.valueOf(pwdChars).chars().mapToObj(c -> "'" + (char) c + "'").collect(Collectors.joining(",", "{", "}"))
        );
    }
}